#!/usr/bin/python

import pickle, sys, time, os.path

from veil import *

if __name__ == "__main__":
    filename = sys.argv[1]
    print filename
    node = filename.split('.')[-2]
    FILE = open( PERF_DIR + "rate." + node + ".csv", "w")
    FILE.close()
    prev = {INPACKETS: 0, OUTPACKETS: 0, PACKETS: 0, RDVPACKETS: 0, DROPPACKETS: 0}
    data_prev = 0
    rdv_prev = 0
    i = 5
    while(True):
        if(os.path.exists(filename)):
            time.sleep(ROUND_TIME)
            perf = pickle.load( open(filename) )
            line = ""
            for j in perf.iterkeys():
                diff = perf[j] - prev[j]
                prev[j] = perf[j] 
                line += "," + str(diff)
            FILE = open( PERF_DIR + "rate." + node + ".csv", "a")
            FILE.write(str(i) + line + "\n")
            FILE.close()
            i += ROUND_TIME
